package twoDayMoreThread;

public class TicketThread implements Runnable{
    private int ticket=100;

   Object obj = new Object();

    @Override
    public void run() {
while (true){
    synchronized (obj){
        if (ticket>0){
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"--->正在卖第"+ticket+"张票");
            ticket--;
        }
    }
}
    }

    public static void main(String[] args) {
        TicketThread ticketThread = new TicketThread();
        Thread thread1 = new Thread(ticketThread);
        Thread thread2 = new Thread(ticketThread);
        Thread thread3 = new Thread(ticketThread);
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
